from django.db.models import Q

from question.models import WordKnowledgepoints
from project.models import Kg


def test():
    DataWarsh().make_kg()


class DataWarsh:
    def make_kp(self):
        kps = WordKnowledgepoints.objects.filter(parent_id__gt=1)
        for kp in kps:
            parent_kp = WordKnowledgepoints.objects.get(point_id=kp.parent_id)
            kp.unit = parent_kp.unit
            kp.save()

    def make_kg(self):
        questions = Kg.objects.filter(~Q(chapter__in=["资料分析", "数量关系", "判断推理", "言语理解与表达", "常识判断", ""]))
        questions_count = questions.count()
        for i in range(questions_count - 1):
            print("---------------%d-----------" % i)
            question = questions[i]
            print("before", question.chapter)
            kps = WordKnowledgepoints.objects.filter(point_name=question.chapter)
            if (kps.count() > 0):
                question.chapter = kps[0].unit
                question.save()
                print("after", kps[0].unit)
            # question.choices = {
            #     "a": question.choice_a,
            #     "b": question.choice_b,
            #     "c": question.choice_c,
            #     "d": question.choice_d
            # }
            # question.save()

    def make_kg_choices(self):
        questions = Kg.objects.all()
        for question in questions:
            question.choices = {
                "a": question.choice_a,
                "b": question.choice_b,
                "c": question.choice_c,
                "d": question.choice_d
            }
            question.save()
